package dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import entity.TbDept;

public class DeptDAO {
	private	Session session=HibernateUtils.getSession();

	public void save(TbDept model) {
		Transaction transaction=session.getTransaction();
		transaction.begin();
		session.persist(model);
		transaction.commit();
	}
	
	public TbDept findById(Integer id) {
		TbDept model=(TbDept) session.get(TbDept.class, id);
		return model;
	}
	
	public List<TbDept> findAll(){
		String hql="from TbDept";
		Query query = session.createQuery(hql);
		return query.list();
	}
	
	public void delete(TbDept model) {
		session.delete(model);
	}
}
